/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.application.ejb.user.impl;

import com.nus.application.ejb.user.EventEjbLocal;
import com.nus.dataaccess.dao.event.Event;
import com.nus.dataaccess.dao.event.dao.EventDao;
/*
import com.nus.dataaccess.dao.user.UserAccount;
import com.nus.dataaccess.dao.user.UserInfo;
import com.nus.dataaccess.dao.user.dao.UserAccountDao;
import com.nus.dataaccess.dao.user.dao.UserInfoDao; */
import com.nus.dataaccess.dao.util.HibernateUtil;
import java.util.List;
import java.util.Map;
import javax.ejb.Stateless;

/**
 *
 * @author
 */
@Stateless
public class EventEjb implements EventEjbLocal {

    @Override
    public String getTestString() {
        return "Hello this is my first EJB";
    }

    @Override
    public List<Event> listAllEvents() {
        return EventDao.getInstance().getAllEvents();
    }

    @Override
    public Event retrieveEventById(Long id) {
        return EventDao.getInstance().getEventById(id);
    }

    @Override
    public List<Event> retrieveEventByConferenceId(Long conferenceId) {
        return EventDao.getInstance().getEventsByConferenceId(conferenceId);
    }

    @Override
    public int getTotalCountEvent(Map<String, Object> filters){
        return EventDao.getInstance().getTotalCount(filters);
    }

    @Override
    public int getTotalCountEventByConferenceId(long conferenceId, Map<String, Object> filters) {
        return EventDao.getInstance().getTotalCountByConferenceId(conferenceId, filters);
    }

    @Override
    public void persistEvent(Event event) {
        try {
            HibernateUtil.beginTransaction();
            EventDao.getInstance().saveOrUpdate(event);
            HibernateUtil.commitTransaction();
        } catch (Exception e) {
            HibernateUtil.rollbackTransaction();
        }
    }

    @Override
    public Event retrieveEventByDescription(String desc){
        return EventDao.getInstance().getEventByDescription(desc);
    }

    @Override
    public List<Event> paginateEvent(int first, int pageSize, String sortField, boolean ascending, Map<String, Object> filters) {
        return EventDao.getInstance().paginate(first, pageSize, sortField, ascending, filters);
    }

    @Override
    public int countPaginateEvent(Map<String, Object> filters) {
        return EventDao.getInstance().getTotalCount(filters);
    }

    @Override
    public void deleteEvent(Event event) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
